package com.liqw.crawler.controller;

import com.liqw.crawler.crawler.impl.WebHouseCrawler;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/crawler")
@RequiredArgsConstructor
@Tag(name = "Crawler API", description = "房源爬虫管理接口")
public class CrawlerController {

    private final WebHouseCrawler webHouseCrawler;

    @PostMapping("/start")
    @Operation(summary = "启动房源爬虫", description = "触发爬虫程序，从目标网站爬取房源信息并保存到本地和数据库")
    public ResponseEntity<String> startCrawler(
            @Parameter(description = "目标网站URL") @RequestParam String url,
            @Parameter(description = "类型") @RequestParam String type) {
        webHouseCrawler.crawlProperty(type, url);
        return ResponseEntity.ok("爬虫任务已启动");
    }
}